package test.study.concurrent.thread._2_executor.scheduled;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class _2_ScheduledThreadPoolExecutor_Main {

    private static ScheduledThreadPoolExecutor POOL = new ScheduledThreadPoolExecutor(10);

    /**
     * 调度一次
     *
     * @param command Callable
     * @param delay   long
     * @param unit    TimeUnit
     */
    public static void main(String[] args) {
        log.info("主线程开始");

        //Step-1:
        ScheduledFuture<Integer> result = POOL.schedule(() -> {
            log.info("fffadsfasdf");
            return 100;
        }, 5, TimeUnit.SECONDS);
        //Step-2:
        try {
            Integer c = result.get();
            log.info(">>>>>> {}", c);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        log.info("主线程结束");
    }
}
